//Build = 2006.05.17
var _XMLMNL_VER		= "3.01.65";
/***********
** 共通変数
***********/
// ユーザー情報
var _USER			= "USER";
var _EMAIL			= "EMAIL";
// パーツリスト履歴管理
var _UDATE_URL		= "UDATE_URL";
// J-POST
var _JPOST			= "JPOST";
var _JPOST_EN		= "JPOST_EN";
var _JPOST_EMAIL	= "JPOST_EMAIL";
var _JPOST_AC		= "JPOST_AC";
var _JPOST_SP		= "JPOST_SP";
var _JPOST_US		= "JPOST_US";
var _JPOST_PS		= "JPOST_PS";
// JASPER
var _JASPER			= "JASPER";
var _JASPER_EN		= "JASPER_EN";
var _JASPER_EMAIL	= "JASPER_EMAIL";
var _JASPER_US		= "JASPER_US";
var _JASPER_PS		= "JASPER_PS";
// 部品発注リンク
var _PO				= "PO";
var _PO_LINK		= "PO_LINK";
var _PO_ENABLE		= "PO_ENABLE";
var _PO_NAME		= "PO_NAME";
var _PO_URL			= "PO_URL";
var _PO_METHOD		= "PO_METHOD";
var _PO_SUBMIT		= "PO_SUBMIT";
var _PO_ID			= "PO_ID";
var _PO_PWD			= "PO_PWD";
// お気に入りリンク
var _FV				= "FV";
var _FV_LINK		= "FV_LINK";
var _FV_INFO		= "FV_INFO";
var _ENABLE			= "EBABLE";
var _NAME			= "NAME";
var _URL			= "URL";
var _METHOD			= "METHOD";
var _SUBMIT			= "SUBMIT";
var _ID				= "ID";
var _PWD			= "PWD";
var _FV_MAX 		= 10;

var _xpath = new Array();
_xpath[_USER] 			= "//username";
_xpath[_EMAIL] 			= "//useremail";
_xpath[_UDATE_URL] 		= "//updatefolder";
_xpath[_JPOST] 			= "//mailstyle/jpost";
_xpath[_JPOST_EN] 		= "//mailstyle/jpost/@enabled";
_xpath[_JPOST_EMAIL] 	= "//mailstyle/jpost/email";
_xpath[_JPOST_AC] 		= "//mailstyle/jpost/ac";
_xpath[_JPOST_SP] 		= "//mailstyle/jpost/sp";
_xpath[_JPOST_US] 		= "//mailstyle/jpost/us";
_xpath[_JPOST_PS] 		= "//mailstyle/jpost/ps";
_xpath[_JASPER] 		= "//mailstyle/jasper";
_xpath[_JASPER_EN]		= "//mailstyle/jasper/@enabled";
_xpath[_JASPER_EMAIL] 	= "//mailstyle/jasper/email";
_xpath[_JASPER_US] 		= "//mailstyle/jasper/us";
_xpath[_JASPER_PS] 		= "//mailstyle/jasper/ps";
_xpath[_PO] 			= "//mypartsorder";
_xpath[_PO_LINK] 		= "//mypartsorder/linkinfo";
_xpath[_PO_ENABLE] 		= "//mypartsorder/linkinfo/@enabled";
_xpath[_PO_NAME] 		= "//mypartsorder/linkinfo/@title";
_xpath[_PO_URL] 		= "//mypartsorder/linkinfo/url";
_xpath[_PO_METHOD] 		= "//mypartsorder/linkinfo/method/@id";
_xpath[_PO_SUBMIT] 		= "//mypartsorder/linkinfo/submit";
_xpath[_PO_ID] 			= "//mypartsorder/linkinfo/userid";
_xpath[_PO_PWD] 		= "//mypartsorder/linkinfo/userpsswrd";
_xpath[_FV] 			= "//myfavorite";
_xpath[_FV_LINK] 		= "//myfavorite/linkinfo";
_xpath[_FV_INFO] 			= new Array();
_xpath[_FV_INFO][_NAME] 	= "@title";
_xpath[_FV_INFO][_URL] 		= "url";
_xpath[_FV_INFO][_METHOD] 	= "method/@id";
_xpath[_FV_INFO][_SUBMIT] 	= "submit";
_xpath[_FV_INFO][_ID] 		= "userid";
_xpath[_FV_INFO][_PWD] 		= "userpsswrd";

var _naviname = _getBrowserName();

// セットアップ - XML
if (document.implementation && document.implementation.createDocument) {
	var _xmlset = document.implementation.createDocument("", "", null);
	_xmlset.async = false;
	_xmlset.selectNodes = myselectNodes;
	_xmlset.selectSingleNode = myselectSingleNode;
	_xmlset.loadXML = myloadXML;
} else if (window.ActiveXObject) {
	var _xmlset = new ActiveXObject("Microsoft.XMLDOM");
	_xmlset.async = false;
}

// インポート用 - XML
if (document.implementation && document.implementation.createDocument) {
	var _xmldummy = document.implementation.createDocument("", "", null);
	_xmldummy.async = false;
	_xmldummy.selectNodes = myselectNodes;
	_xmldummy.selectSingleNode = myselectSingleNode;
	_xmldummy.loadXML = myloadXML;
} else if (window.ActiveXObject) {
	var _xmldummy = new ActiveXObject("Microsoft.XMLDOM");
	_xmldummy.async = false;
}

// セットアップ - XSL
if (document.implementation && document.implementation.createDocument) {
	var _xslset = document.implementation.createDocument("", "", null);
	_xslset.async = false;
} else if (window.ActiveXObject) {
	var _xslset = new ActiveXObject("Microsoft.XMLDOM");
	_xslset.async = false;
}

// 部品表 - XML
if (document.implementation && document.implementation.createDocument) {
	var _xmldoc = document.implementation.createDocument("", "", null);
	_xmldoc.async = false;
	_xmldoc.selectNodes = myselectNodes;
	_xmldoc.selectSingleNode = myselectSingleNode;
} else if (window.ActiveXObject) {
	var _xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	_xmldoc.async = false;
}

// 部品表 - XSL
if (document.implementation && document.implementation.createDocument) {
	var _xsldoc = document.implementation.createDocument("", "", null);
	_xsldoc.async = false;
} else if (window.ActiveXObject) {
	var _xsldoc = new ActiveXObject('Microsoft.XMLDOM');
	_xsldoc.async = false;
}

// 差分部品表 - XML
if (document.implementation && document.implementation.createDocument) {
	var _xmldoc_d = document.implementation.createDocument("", "", null);
	_xmldoc_d.async = false;
	_xmldoc_d.selectNodes = myselectNodes;
	_xmldoc_d.selectSingleNode = myselectSingleNode;
} else if (window.ActiveXObject) {
	var _xmldoc_d = new ActiveXObject('Microsoft.XMLDOM');
	_xmldoc_d.async = false;
}

// 部品発注一覧 - XML
if (document.implementation && document.implementation.createDocument) {
	var _xmlodr = document.implementation.createDocument("", "", null);
	_xmlodr.async = false;
	_xmlodr.selectNodes = myselectNodes;
	_xmlodr.selectSingleNode = myselectSingleNode;
	_xmlodr.loadXML = myloadXML;
} else if (window.ActiveXObject) {
	var _xmlodr = new ActiveXObject('Microsoft.XMLDOM');
	_xmlodr.async = false;
}

// 部品発注一覧 - XSL
if (document.implementation && document.implementation.createDocument) {
	var _xslodr = document.implementation.createDocument("", "", null);
	_xslodr.async = false;
} else if (window.ActiveXObject) {
	var _xslodr = new ActiveXObject('Microsoft.XMLDOM');
	_xslodr.async = false;
}

// TOC - XML
if (document.implementation && document.implementation.createDocument) {
	var _xmltoc = document.implementation.createDocument("", "", null);
	_xmltoc.async = false;
	_xmltoc.selectNodes = myselectNodes;
	_xmltoc.selectSingleNode = myselectSingleNode;
} else if (window.ActiveXObject) {
	var _xmltoc = new ActiveXObject('Microsoft.XMLDOM');
	_xmltoc.async = false;
}

// TOC - XML
if (document.implementation && document.implementation.createDocument) {
	var _xmltoc2 = document.implementation.createDocument("", "", null);
	_xmltoc2.async = false;
	_xmltoc2.selectNodes = myselectNodes;
	_xmltoc2.selectSingleNode = myselectSingleNode;
} else if (window.ActiveXObject) {
	var _xmltoc2 = new ActiveXObject('Microsoft.XMLDOM');
	_xmltoc2.async = false;
}

// TOC -XSL
if (document.implementation && document.implementation.createDocument) {
	var _xsltoc = document.implementation.createDocument("", "", null);
	_xsltoc.async = false;
} else if (window.ActiveXObject) {
	var _xsltoc = new ActiveXObject('Microsoft.XMLDOM');
	_xsltoc.async = false;
}

// 電圧値表 - XML
if (document.implementation && document.implementation.createDocument) {
	var _xmlvolt = document.implementation.createDocument("", "", null);
	_xmlvolt.async = false;
	_xmlvolt.selectNodes = myselectNodes;
	_xmlvolt.selectSingleNode = myselectSingleNode;
} else if (window.ActiveXObject) {
	var _xmlvolt = new ActiveXObject('Microsoft.XMLDOM');
	_xmlvolt.async = false;
}

// 電圧値表 - XSL
if (document.implementation && document.implementation.createDocument) {
	var _xslvolt = document.implementation.createDocument("", "", null);
	_xslvolt.async = false;
} else if (window.ActiveXObject) {
	var _xslvolt = new ActiveXObject('Microsoft.XMLDOM');
	_xslvolt.async = false;
}

// 波形図表 - XSL
if (document.implementation && document.implementation.createDocument) {
	var _xslwave = document.implementation.createDocument("", "", null);
	_xslwave.async = false;
} else if (window.ActiveXObject) {
	var _xslwave = new ActiveXObject('Microsoft.XMLDOM');
	_xslwave.async = false;
}

/***********
** 共通関数
***********/
document.getElementsByClassName = function (tagName, className) {
	if (className == "") {
		return null;
	}
	var i, j, objClass;
	var objAll = document.getElementsByTagName ? document.getElementsByTagName(tagName) : document.all;
	var objCN = new Array();
	for (i = 0; i < objAll.length; i++) {
		objClass = objAll[i].className.split(/\s+/);
		for (j = 0; j < objClass.length; j++) {
			if (objClass[j] == className) {
				objCN.push(objAll[i]);
				break;
			}
		}
	}
	return objCN;
}

function _getLocationSearch() {
	var qstr = new Array();
	if (location.search.length > 1) {
		var q_array = location.search.substr(1).split("&");
		for (var n in q_array) {
			qstr.push(q_array[n].split("="));
		}
	}
	return qstr;
}

function _getBrowserName() {
	var str = navigator.appName.toUpperCase();
	if (str.indexOf("NETSCAPE") >= 0) return ("NS");
	if (str.indexOf("EXPLORER") >= 0) return ("IE");
	return ("UNKNOWN");
}

function _getBrowserLang() {
	if (_naviname == "IE") {
		//return navigator.browserLanguage;
		//return navigator.systemLanguage;
		return navigator.userLanguage;
	} else if (_naviname == "NS"){
		return navigator.language.split("-")[0];
	}
}

function _delPreviousCookie() {
	// ユーザー情報
	if (_getCookie("UserName") != "") {
		_setCookie(_USER, _getCookie("UserName"))
	}
	_setCookie("UserName", "");
	if (_getCookie("UserEmail") != "") {
		_setCookie(_EMAIL, _getCookie("UserEmail"))
	}
	_setCookie("UserEmail", "");
	// マイノート
	_setCookie("MyNoteFolder", "");
	// パーツリスト履歴管理
	if (_getCookie("UpdateFolder") != "") {
		_setCookie(_UDATE_URL, _getCookie("UpdateFolder"))
	}
	_setCookie("UpdateFolder",	"");
	// J-POST
	if (_getCookie("JpostEnabled") != "") {
		var s = "";
		s += _getCookie("JpostMail") + "|";
		s += _getCookie("JpostAC") + "|";
		s += _getCookie("JpostSP") + "|";
		s += _getCookie("JpostUS") + "|";
		s += _getCookie("JpostPS");
		_setCookie(_JPOST, s);
	}
	_setCookie("JpostEnabled",	"");
	_setCookie("JpostMail",	"");
	_setCookie("JpostAC", "");
	_setCookie("JpostSP", "");
	_setCookie("JpostUS", "");
	_setCookie("JpostPS", "");
	_setCookie("JpostFolder", "");
	// JASPER
	if (_getCookie("JasperEnabled") != "") {
		var s = "";
		s += _getCookie("JasperMail") + "|";
		s += _getCookie("JasperUS") + "|";
		s += _getCookie("JasperPS");
		_setCookie(_JASPER, s);
	}
	_setCookie("JasperEnabled",	"");
	_setCookie("JasperMail",	"");
	_setCookie("JasperUS", "");
	_setCookie("JasperPS", "");
	// お気に入りリンク
	if (_getCookie("FavoriteLength") != "") {
		for (var i = 0; i < _FV_MAX; i++) {
			var fv = _getCookie("Favorite_" + i).split(";;");
			var s = "";
			for (var j = 0; j < fv.length - 1; j++) {
				if (fv[j].split("==")[0] == "FavoriteMethod") {
					switch (fv[j].split("==")[1]) {
						case "":		s += "0" + "|"; break;
						case "get":		s += "1" + "|"; break;
						case "post":	s += "2" + "|"; break;
					}
				} else {
					s += fv[j].split("==")[1] + "|";
				}
			}
			 _setCookie("Favorite_" + i, "");
			 if (_getCookie("FavoriteLength") != "0") {
			 	_setCookie(_FV + (i + 1), s);
			 }
		}
	}
	_setCookie("FavoriteLength", "");
	for (var i = 0; i < 15; i++) {
		_setCookie("Favorite_" + i, "");
	}
}

function _setCookie(sName, sValue) {
	if ((location.protocol.indexOf("file") != -1) && (_naviname == "IE")) {
		splitstr = "\\";
	} else {
		splitstr = "/";
	}
	var patharray = location.pathname.split(splitstr);
	var pathstr = patharray[0];
	for (var i = 1; i < patharray.length - 4; i++) {
		pathstr += splitstr + patharray[i];
	}
	if (pathstr.substring(0, 1) != "/") {
		pathstr = "/" + pathstr;
	}
	if (sValue != "") {
		var expires = "Thu, 1-Jan-2030 00:00:00 GMT";
	} else {
		var expires = "Fri, 31-Dec-1999 23:59:59 GMT";
	}
	document.cookie = sName + "=" + escape(sValue) + "; expires=" + expires + "; path=" + unescape(pathstr);
}

function _getCookie(sName) {
	var cookieArray = document.cookie.split('; ');
	for (var i = 0; i < cookieArray.length; i++) {
		var aCrumb = cookieArray[i].split('=');
		if ((sName == aCrumb[0]) && (aCrumb[1] != null)) {
			return unescape(aCrumb[1]);
		}
	}
	return '';
}

function myselectNodes() {		// for Firefox Only
	if (_naviname == "NS") {
		if (this.documentElement == null) {
			return null;
		}
		var context = this.documentElement;
		var type = XPathResult.ORDERED_NODE_SNAPSHOT_TYPE;
		var resolver = this.createNSResolver(this.documentElement);
		var expression = this.createExpression(myselectNodes.arguments[0], resolver);
		var result = new Object();
		result = expression.evaluate(context, type, null);
		result.length = result.snapshotLength;
		result.item = result.snapshotItem;
		return result;
	}
}

function myselectSingleNode() {		// for Firefox Only
	if (_naviname == "NS") {
		if (this.documentElement == null) {
			return null;
		}
		var context = this.documentElement;
		var type = XPathResult.FIRST_ORDERED_NODE_TYPE;
		var resolver = this.createNSResolver(this.documentElement);
		var expression = this.createExpression(myselectSingleNode.arguments[0], resolver);
		var result = new Object();
		result = expression.evaluate(context, type, null);
		result = result.singleNodeValue;
		if (result != null) {
			if (result.hasChildNode) {
				result.text = result.firstChild.nodeValue;
			} else {
				result.text = "";
			}
		}
		return result;
	}
}

function myloadXML() {		// for Firefox Only
	if (_naviname == "NS") {
		if (this.documentElement == null) {
			return null;
		}
		var parser = new DOMParser();
		var result = new Object();
		result = parser.parseFromString(myloadXML.arguments[0], "text/xml");
		result.async = false;
		result.selectNodes = myselectNodes;
		result.selectSingleNode = myselectSingleNode;
		result.loadXML = myloadXML;
		return result;
	}
}

function _xmltransform(xmlobj, xslobj, params, targetid) {
	if (_naviname == "NS") {
		var xslProc = new XSLTProcessor();
		xslProc.importStylesheet(xslobj);
		for (id in params) {
	    	xslProc.setParameter(null, id, params[id]);
		}
		if (xmlobj != null) {
			var xmldocment = xslProc.transformToDocument(xmlobj);
			if (targetid != "") {
				document.getElementById(targetid).innerHTML = xmldocment.documentElement.innerHTML;
			} else {
				//return "<html>" + xmldocment.documentElement.innerHTML + "</html>";
				return xmldocment.documentElement.innerHTML;
			}
		}
	} else if (_naviname == "IE") {
		for (id in params) {
			var paramNode = xslobj.getElementsByTagName("xsl:param[@name='" + id + "']");
			paramNode.item(0).text = params[id];
		}
		if (xmlobj != null) {
			if (targetid != "") {
				eval(targetid).innerHTML = xmlobj.transformNode(xslobj);
			} else {
				return xmlobj.transformNode(xslobj);
			}
		}
	}
}

function _get_part2_FileName() {
	if (_xmltoc.documentElement != null) {
		var mno = _xmltoc.selectSingleNode("//MNO").firstChild.nodeValue.toLowerCase();
		for (var i = mno.length; i < 6; i++) {
			mno += "_";
		}
		return mno + "l00a.xml";
	}
}

function _getvolt_FileName() {
	if (_xmltoc.documentElement != null) {
		var mno = _xmltoc.selectSingleNode("//MNO").firstChild.nodeValue.toLowerCase();
		for (var i = mno.length; i < 6; i++) {
			mno += "_";
		}
		return mno + "v001.xml";
	}
}

function _getOrderDisable() {
	if ((_getCookie(_JPOST) != "") || (_getCookie(_JASPER) != "") || (_getCookie(_PO) != "")) {
		return '1';
	} else {
		return '0';
	}
}

function _updatePlist() {
	var UpdateFolder = _getCookie(_UDATE_URL);
	if (UpdateFolder != "") {
		var updateFname = UpdateFolder + _get_part2_FileName();
	} else {		// URL or パス未設定時はカレント内
		//var updateFname = "../" + _get_part2_FileName();
		var updateFname = _get_part2_FileName();
	}
	var exist = true;
	try {
		_xmldoc_d.load(updateFname);
	} catch(e) {
		exist = false;
	}
	if (exist) {
		if (_xmldoc_d.selectSingleNode("//PARTSLIST") == null) {	// 既存ファイルが存在しない場合
			return;
		} else {
			var org_node = _xmldoc.selectSingleNode("//PARTSLIST");
			var nodelist = _xmldoc_d.selectNodes("//PARTSLIST/ROW");
		    for (var i = 0; i < nodelist.length; i++) {
				org_node.appendChild(nodelist.item(i).cloneNode(true));
			}
		}
	}
}

function _absPath() {
	// Firefoxの場合、相対パス指定では何故かパスがずれる？　原因不明。
	// 故に絶対パス指定としてみる。
	var patharray = location.href.split("/");
	var pathstr = patharray[0];
	for (var i = 1; i < patharray.length - 2; i++) {
		pathstr += "/" + patharray[i];
	}
	return pathstr;
}

function _showTextWin(text, path, btn) {
	var TextWin = window.open(path + "null.html", "TextWin", "scrollbars=yes,resizable=yes,menubar=no,directories=no,status=no,location=no,width=480,height=340");
	TextWin.document.writeln("<html>");
	TextWin.document.writeln("<head>");
	TextWin.document.writeln("<link rel='stylesheet' type='text/css' href='../js/mnlstyle.css' />");
	TextWin.document.writeln("</head>");
	TextWin.document.writeln("<body>");
	TextWin.document.writeln("<table width='100%'><tr align='center'><td>");
	TextWin.document.writeln("<textarea name='textarea' cols='52' rows='13' wrap='off' id='textarea' readonly='readonly'>");
	TextWin.document.writeln(text);
	TextWin.document.writeln("</textarea><p />");
	TextWin.document.writeln("<input type='button' name='btn' value='" + btn + "' onclick='window.close();'/>");
	TextWin.document.writeln("</td></tr></table>");
	TextWin.document.writeln("</body>");
	TextWin.document.writeln("</html>");
	TextWin.document.close();
	TextWin.focus();
}

function _myFV() {
	var maxnode = 0;
	var s;
	var rtn = "";
	for (var i = 1; i <= _FV_MAX; i++) {
		s = _getCookie(_FV + i);
		if (s != "") {
			maxnode = i;
		} else {
			break;
		}
	}
	for (var i = 1; i <= maxnode; i++) {
		s = _getCookie(_FV + i);
		if (s != "") {
			rtn += s.split("|")[0];	// TITLE
			if (s.split("|")[3].indexOf('$(CurModel)') != -1) {
				rtn += "@m!";
			} else if (s.split("|")[3].indexOf('$(CurPartNo)') != -1) {
				rtn += "@p!";
			} else if (s.split("|")[3].indexOf('$(CurPartName)') != -1) {
				rtn += "@n!";
			} else {
				rtn += "@!";
			}
		}
	}
	if (rtn != "") {
		rtn = "&v=" + escape(rtn);
	}
	return rtn + "&l=" + _getBrowserLang();
}

function _js_docwrite(str) {	//【対策】KB912812（MS06-013）InternetExplorer用の累積的なセキュリティ更新プログラム
	document.write(str);
}
